package com.CmJava.crowd.controller;


import com.CmJava.crowd.entity.CrowdException;
import com.CmJava.crowd.entity.ResultEntity;
import com.CmJava.crowd.service.AdminService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpServletRequest;


@Controller
public class testController {
    @Autowired
    AdminService adminService;


    @RequestMapping("test/controller1")
    @ResponseBody
    // Spring会填充ModelMap、HttpServletRequest参数进去
    // ModelMap即Model，封装数据
    public ResultEntity<String> test(ModelMap modelMap, HttpServletRequest request){
        System.out.println(adminService);
        if(true) {
            throw new CrowdException(CrowdException.ACCESS_EXCEPTION);
        }
        return ResultEntity.successWithData(new String("666"));
    }
    @RequestMapping("test/controller")
    public String acc(ModelMap modelMap, HttpServletRequest request){
        modelMap.addAttribute(new String());
        /* 为了避免转发后页面静态资源无法以相对路径获取到
          所以重定向为/index.html，即根目录（项目路径，工程的webapp路径）下的index.html
        */
        return "redirect:/index.html";
    }
    @RequestMapping("controller")
    public String accd(ModelMap modelMap, HttpServletRequest request){
        /*
          为了使用转发，请求路径必须对应好转发页面的路径，这样也行
        */
        return "index";
    }
    @RequestMapping("test/controller4")
    public String accT(ModelMap modelMap, HttpServletRequest request){

        /* 为了避免转发后页面静态资源无法以相对路径获取到
          所以重定向为/index.html，即根目录（项目路径，工程的webapp路径）下的index.html
        */
        return "index";
    }
}

